package com.mall.malladminbackend.controller;

import com.mall.malladminbackend.dto.SysDeptDto;
import com.mall.malladminbackend.model.R;
import com.mall.malladminbackend.service.SysDeptService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.security.Principal;

/**
 * 2022/8/11
 * 一杯茶，一根烟，一个bug解一天
 */
@RestController
@RequestMapping("/dept")
@AllArgsConstructor
public class SysDeptController {

    private SysDeptService  sysDeptService;

//  查询所有集团及下面所有子公司
    @GetMapping
    public R getSysDept(){
        return sysDeptService.getSysDeptTree();
    }
//    添加公司
    @PostMapping
    public R  addSysDept(@RequestBody SysDeptDto sysDeptDto, Principal principal){
        return sysDeptService.addSysDept(sysDeptDto,principal);
    }
//    编辑
    @PutMapping
    public R  updateSysDept(@RequestBody SysDeptDto sysDeptDto,Principal principal){
        return sysDeptService.updateDept(sysDeptDto,principal);
    }
    @DeleteMapping("/{id}")
    public R deleteSysDept(@PathVariable("id") Integer id){
           return sysDeptService.deleteDept(id);
    }

}
